/**
  ******************************************************************************
  * @author     Chris
  * @since      2024/6/21 10:50
  *
  * @file       pd_usart.h
  * @brief      Header file of Xxx hardware driver.
  *
  * @note       This file contains the Xxx object declaration.
  *
  * @warning    None.
  ******************************************************************************
  * Change Logs:
  *   Date          Author       Notes
  *   2024/6/21     Chris        the first version
  *
  ******************************************************************************
  */


#ifndef JLC_SKY_USART_H
#define JLC_SKY_USART_H

#include "stm32f407xx.h"
#include "pd_gpio.h"
#include "drivers.h"

typedef struct USARTDef USART;

struct USARTDef {
    USART_TypeDef *USARTx;
    GPIOList *gpioList;

    uint8_t rxFlag;
    uint8_t rxData;

    uint32_t BaudRate;
    uint32_t DataWidth;
    uint32_t StopBits;
    uint32_t Parity;
    uint32_t TransferDirection;
    uint32_t HardwareFlowControl;
    uint32_t OverSampling;

    void (*init)(USART *this, IRQn_Type irQnType, uint32_t PreemptPriority, uint32_t SubPriority);

    void (*send_byte)(USART *this, uint8_t byte);

    void (*send_array)(USART *this, const uint8_t *array, uint16_t length);

    void (*send_string)(USART *this, char *String);

    void (*send_num)(USART *this, uint32_t number, uint8_t length);

    void (*printf)(USART *this, char *format, ...);

    uint8_t (*get_rx_flag)(USART *this);
};

extern const struct USARTClass {
    USART *(*build)(USART_TypeDef *USARTx, GPIOList *gpioList, uint32_t BaudRate);
} USARTBuilder;

#endif //JLC_SKY_USART_H
